package org.gos.mission.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.gos.mission.domain.User;

/**
 * @author tony
 * @version 1.0
 */
public class LoginDaoMySQLImpl {

	public User login(Connection conn, String username, String password) {
		User user = new User();
		Statement st =null;
		try {
			st = conn.createStatement();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		ResultSet rs = null;

		try {
			
			
			rs = st.executeQuery("select * from t_user where username=\""+username+"\" and password =\""+password+"\"");
			
			
			if(rs.next()){
				user.setId(rs.getInt(1));
				user.setUsername(rs.getString(2));
				user.setPassword(rs.getString(3));
				
			}else {
				return null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return user;
	}
}
